/*
 * UserFeedback
 * 
 * Version information:1.0
 *
 * Date: 19/11/2012
 */

import javax.swing.JFrame;
import javax.swing.JOptionPane;

/**
 * @author dv11rlm
 */
public class UserFeedback extends JFrame {

    /**
     * variable satatuses and serial number.
     */
    public static final int DEFAULT_DIALOG = 0;
    public static final int ERROR_DIALOG = 1;
    public static final int WARNING_DIALOG = 2;
    private static final long serialVersionUID = 1L;

    /**
     * Decides what type of messageLayout should be used. dialogIndex
     * can't be out of bound(0-2) or a IndexOutOfBoundException will
     * be thrown.
     * 
     * @param message
     *            information given to the user
     * @param value
     *            from 0-2 used for deciding what dialog-layout that
     *            should be used
     */

    public UserFeedback(String message, int dialogType) {
	switch (dialogType) {
	case DEFAULT_DIALOG:
	    defaultDialog(message);
	    break;
	case WARNING_DIALOG:
	    WarningDialog(message);
	    break;
	case ERROR_DIALOG:
	    errorDialog(message);
	    break;
	default:
	    throw new IndexOutOfBoundsException();
	}

    }

    /**
     * Opens a window showing the user a message using default dialog.
     * 
     * @param message
     *            information given to the user
     */

    private void defaultDialog(String message) {
	setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	JOptionPane.showMessageDialog(this, message);
    }

    /**
     * Opens a window showing the user a message using warning dialog.
     * The title will be set to Warning.
     * 
     * @param message
     *            information given to the user
     * @see JOptionPane
     */

    private void WarningDialog(String message) {
	setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	JOptionPane.showMessageDialog(this, message, "Warning",
		JOptionPane.WARNING_MESSAGE);
    }

    /**
     * Opens a window showing the user a message using Error dialog.
     * The title will be set to Error.
     * 
     * @param message
     *            information given to the user
     * @see JOptionPane
     */

    private void errorDialog(String message) {
	setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	JOptionPane.showMessageDialog(this, message, "Error",
		JOptionPane.ERROR_MESSAGE);
    }
}
